package com.yy.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.util.Optional;

//车辆实体

@Data
@TableName("vehicle")
public class Vehicle {
    @TableId(type= IdType.AUTO)
    private Long id;
    @TableField("licence_plate")
    private String licencePlate;//车牌号
    private String picUrl;//车辆入场照片存储位置
    @TableField("is_active")
    private boolean isActive;//入场、离场标记，true：入场，否则是离场
    @TableField("parking_lot_id")
    private  ParkingLot parkingLot;//关联的停车场
    public Vehicle(){}
    public Vehicle(Vehicle entity){
        this.id= entity.id;
        this.licencePlate= entity.licencePlate;
        this.isActive= entity.isActive;
        this.picUrl= entity.picUrl;
        //去if语句
        /*Optional.ofNullable方法，将entity.parkingLot包装成Optional
         *ifPresent方法，传入Lambda表达式，该表达式针对Optional进行非空判断
         * 如果非空，完成值传递，否则不做任何事情*/
        if(entity.parkingLot!=null){
            this.parkingLot.setId(entity.parkingLot.getId());
            this.parkingLot.setName(entity.parkingLot.getName());
            this.parkingLot.setVolumetric(entity.parkingLot.getVolumetric());
        }
        Optional.ofNullable(entity.parkingLot)
                .ifPresent(x->{
                    this.parkingLot= new ParkingLot();
                    this.parkingLot.setId(x.getId());
                    this.parkingLot.setName(x.getName());
                    this.parkingLot.setVolumetric(x.getVolumetric());
                });
    }

}